//
//  SmallDecisionsFxqResultViewController.h
//  SmallDecisions
//
//  Created by 李付雄 on 2025/08/28.
//

#import "SmallDecisionsFxqResultViewController.h"

@interface SmallDecisionsFxqResultViewController ()

@property (nonatomic,strong) UIImageView *resultImageView;

@end

@implementation SmallDecisionsFxqResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIView *containerView = [[UIView alloc] init];
    containerView.backgroundColor = SmallDecisionsPurpleColor;
    containerView.layer.cornerRadius = 10;
    containerView.layer.masksToBounds = YES;
    [self.view addSubview:containerView];
    [containerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.centerY.mas_equalTo(0);
    }];

    UILabel *resultTitleLabel = [[UILabel alloc] init];
    resultTitleLabel.textColor = SmallDecisionsThemeColor;
    resultTitleLabel.text = self.title;
    resultTitleLabel.font = SmallDecisionsSetBoldFontSize(24);
    resultTitleLabel.textAlignment = 1;
    [containerView addSubview:resultTitleLabel];
    [resultTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];


    UIImageView *resultImageView = [[UIImageView alloc] init];
    resultImageView.contentMode = UIViewContentModeScaleAspectFit;
    [resultImageView setImage:[UIImage imageNamed:self.resultImageName]];
    [containerView addSubview:resultImageView];
    [resultImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(resultTitleLabel.mas_bottom).mas_offset(10);
        if(self.resultImageName.length) {
            make.height.mas_equalTo(resultImageView.mas_width).offset(0.7);
        } else {
            make.height.mas_equalTo(0);
        }

    }];
    self.resultImageView = resultImageView;


    UILabel *resultContentLabel = [[UILabel alloc] init];
    resultContentLabel.textColor = SmallDecisionsThemeFontColor;
    resultContentLabel.text = self.resultMsg;
    resultContentLabel.font = SmallDecisionsSetBoldFontSize(32);
    resultContentLabel.numberOfLines = 0;
    resultContentLabel.textAlignment = 1;
    [containerView addSubview:resultContentLabel];
    [resultContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(resultImageView.mas_bottom).mas_offset(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
    }];

    UIButton *resultSureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [resultSureBtn setTitle:@"确定" forState:UIControlStateNormal];
    [resultSureBtn setTitleColor:SmallDecisionsThemeFontColor forState:UIControlStateNormal];
    [resultSureBtn setTitleColor:[UIColor clearColor] forState:UIControlStateHighlighted];
    resultSureBtn.titleLabel.font = SmallDecisionsSetBoldFontSize(16);
    resultSureBtn.layer.cornerRadius = 25;
    resultSureBtn.layer.masksToBounds = YES;
    resultSureBtn.backgroundColor = SmallDecisionsThemeColor;
    [resultSureBtn addTarget:self action:@selector(resultSureBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [containerView addSubview:resultSureBtn];
    [resultSureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(50);
        make.width.mas_equalTo(180);
        make.top.equalTo(resultContentLabel.mas_bottom).offset(40);
        make.bottom.mas_equalTo(-20);
        make.centerX.mas_equalTo(0);
    }];
}

- (void)setResultImageName:(NSString *)resultImageName {
    _resultImageName = resultImageName;
    if(resultImageName.length) {
        [self.resultImageView setImage:[UIImage imageNamed:resultImageName]];
        [self.resultImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(self.resultImageView.mas_width).offset(0.7);
        }];

    }
}

- (void)resultSureBtnAction {
    [SmallDecisionsNavigatorManager dismissViewControllerAnimated:YES completion:nil];
}

@end
